package v1

import (
	"daily-blog/model"
	"daily-blog/pkg"
	"daily-blog/service"
	"github.com/gin-gonic/gin"
)

func CreateTag(c *gin.Context) {
	tagName := c.PostForm("tag_name")
	tagId := c.PostForm("tag_id")
	if tagName == "" {
		pkg.FailWithMessage("标签名为空", c)
		return
	}
	if tagId == "" {
		// 生成id
		tagId = pkg.GenUUID()
		tag := &model.Tag{TagName: tagName, TagId: tagId}
		// 创建
		if ok := service.CreateTag(tag); !ok {
			pkg.Fail(c)
			return
		}
		pkg.Ok(c)
		return
	}
	if ok := service.UpdateTag(tagId, tagName); !ok {
		pkg.Fail(c)
		return
	}
	pkg.Ok(c)
}
func DeleteTag(c *gin.Context) {
	tagId := c.PostForm("tag_id")
	if tagId == "" {
		pkg.FailWithMessage("标签id为空", c)
		return
	}
	if ok := service.DeleteTagById(tagId); !ok {
		pkg.Fail(c)
		return
	}
	pkg.Ok(c)
}
func GetTagList(c *gin.Context) {
	tagList, ok := service.GetTagList()
	if !ok {
		pkg.Fail(c)
		return
	}
	pkg.OkWithData(tagList, c)
}
func UpdateTag(c *gin.Context) {

	//tagName := c.PostForm("tag_name")
	//if tagId == "" {
	//	pkg.FailWithMessage("标签id为空", c)
	//	return
	//}
	//if tagName == "" {
	//	pkg.FailWithMessage("标签名为空", c)
	//	return
	//}

}
